import router from "@koa/router"
import jwt from 'jsonwebtoken'
import adminService from '../services/admin'
import { expTime, secret  } from '../app.config'

const trouter = router()
trouter.prefix("/api/user")
trouter.post('/login', async ctx=>{
    let query  = await adminService.getAdmin(ctx.query);
    let { body } = ctx.request
    let username = body.username

    let token = jwt.sign({
        data: username,
        exp: expTime //过期时间 - 1小时
    }, secret)

    ctx.body = {
        status:"SUCCEED",
        data: query,
        token
    }
})


export default trouter